package com.example.thread.demo.task;

import java.util.concurrent.Callable;

/**
 * @author zhy
 * @date 2020/4/15 6:29 下午
 * @description
 */
public class MyTask implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int total = 0;
        try {
            for (int i = 0; i < 10; i++) {
                System.out.println("thread: " + Thread.currentThread().getName() + " i = " + i);
                Thread.sleep(1000);
                total += i;
            }
        } catch (InterruptedException e) {
            System.out.println("task is interrupted");
            return 0;
        }
        return total;
    }
}
